<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../../php/config/database.php";
require_once "adminDb.php";
$adminDb=new AdminDb();
$user=$_POST['user'];
$password=$_POST['pass'];
$code=$_POST['code'];
$pass="d5381974dfe482a6eb1093eaf6f7b988";
$addtime=time();
$password=md5($password);
$datea=$adminDb->selectAdminA($user);
if($code===$pass) {

    if ($datea == null) {
        session_start();
        $_SESSION['user'] = $user;
        $data = $adminDb->add_admin($user, $password, $addtime);
        try {
            $result = $data;
            if ($result) {
                $dat = array(
                    'message' => "注册成功",
                );
                echo json_encode($dat);
            } else {
                $dat = array(

                    'message' => "注册失败",

                );
                echo json_encode($dat);

            }
        } catch (Exception $e) {

            // 回滚事务
            // $pdo->rollback();
            echo $e->getMessage();
        }

    } else {

        $dat = array(

            'message' => "该账号以及存在，请登陆",
            'data' => $datea,

        );
        echo json_encode($dat);


    }
}
else{

    $dat = array(

        'message' => "对不起，邀请码错误，注册失败",
        'data' => $datea,

    );
    echo json_encode($dat);
}

